
/*
 * Copyright (C) 2010 Young, Fey <fey.young@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package com.youngfey.chess

/**
 *
 * @author Young, Fey <fey.young@gmail.com>
 */
enum Piece {
    WHITE_KING(Side.WHITE, PieceType.KING, 'K'),
    WHITE_QUEEN(Side.WHITE, PieceType.QUEEN, 'Q'),
    WHITE_ROOK(Side.WHITE, PieceType.ROOK, 'R'),
    WHITE_BISHOP(Side.WHITE, PieceType.BISHOP, 'B'),
    WHITE_KNIGHT(Side.WHITE, PieceType.KNIGHT, 'N'),
    WHITE_PAWN(Side.WHITE, PieceType.PAWN, 'P'),
    BLACK_KING(Side.BLACK, PieceType.KING, 'k'),
    BLACK_QUEEN(Side.BLACK, PieceType.QUEEN, 'q'),
    BLACK_ROOK(Side.BLACK, PieceType.ROOK, 'r'),
    BLACK_BISHOP(Side.BLACK, PieceType.BISHOP, 'b'),
    BLACK_KNIGHT(Side.BLACK, PieceType.KNIGHT, 'n'),
    BLACK_PAWN(Side.BLACK, PieceType.PAWN, 'p'),

    static Piece getInstance(String notation) {
        def p = map.get(notation)
        if(p == null) {
            throw new IllegalArgumentException("Illegal notation: $notation")
        }
        p
    }

    static Piece getInstance(Side side, PieceType type) {
        Piece.enumConstants[ side.ordinal() * 6 + type.ordinal() ]
    }

    private Piece(side, type, notation) {
        this.side = side
        this.type = type
        this.notation = notation
        if(map == null) map = [:]
        map.put(notation, this)
    }

    final Side side
    final PieceType type
    final notation

    private static map 
}


